package ru.kisa_wst.parse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;


public class URLTracker {
	private Collection<String> pageUrls = null;
	private String domain;
	private static HashSet<String> totalUrls = new HashSet<String>();
	
	public URLTracker(String domain,Collection<String> pageUrls){
		this.pageUrls = pageUrls;
	}

	public Collection<String> getUrlCollection() {
		return totalUrls;
	}
	
	public void start() throws IOException{
		for(String url:pageUrls){
			System.err.println("working with "+url+"....");
			Parser parser = new Parser();
			Collection<String> links =parser.getLinks(url);
			ArrayList<String> tempList= new ArrayList<String>();
			for(String str:links){
				if(!totalUrls.contains(str)) tempList.add(str); 
			}
			totalUrls.addAll(tempList);
			//System.out.println(totalUrls);
			URLTracker tracker = new URLTracker(domain,tempList);
			tracker.start();
			System.err.println("working with utl end");
			System.err.println("totalLinks="+totalUrls.size());
		}
	}
}
